import { Injectable } from '@angular/core';
import { Action, State, StateContext } from '@ngxs/store';
import { System } from './system.action';

export interface SystemStateModel {
  /**
   * 侧边栏是否关闭
   * true为关闭，false为打开
   */
  nzCollapsed: boolean;
}

@State<SystemStateModel>({
  name: 'system',
  defaults: {
    nzCollapsed: false,
  },
})
@Injectable({
  providedIn: 'root',
})
export class SystemState {
  @Action(System.CollapsedOpen)
  collapsedOpen({patchState}: StateContext<SystemStateModel>) {
    patchState({
      nzCollapsed: false,
    });
  }

  @Action(System.CollapsedClose)
  collapsedClose({patchState}: StateContext<SystemStateModel>) {
    patchState({
      nzCollapsed: true,
    });
  }

  @Action(System.CollapsedReversal)
  collapsedReversal({patchState, getState}: StateContext<SystemStateModel>) {
    let state = getState();
    patchState({
      nzCollapsed: !state.nzCollapsed,
    });
  }

}
